import zipfile,os
def zip(url,isdetail=False,compresslevel=5):
    zip_url=url+".zip"
    file=zipfile.ZipFile(zip_url,"w",zipfile.ZIP_DEFLATED,compresslevel=compresslevel)
    for dirpath,dirname,filenames in os.walk(url):
        fpath=dirpath.replace(url,"")
        fpath=fpath and fpath+os.sep or ""
        for filename in filenames:
            file.write(os.path.join(dirpath,filename),fpath+filename)
            if isdetail:
                print(fpath+filename)
    file.close()
    return zip_url
def unzip(zip_url,out_url=None,compresslevel=5):
    if out_url is None:
        out_url=zip_url.replace(".zip","")
    try:
        with zipfile.ZipFile(zip_url, "r", zipfile.ZIP_DEFLATED,compresslevel=compresslevel) as f:
            f.extractall(out_url)  ##将文件解压到指定目录，解压密码为root
    except Exception as e:
        print("异常对象的内容是:%s" % e)
    finally:
        f.close()
